import Vuex from '@wepy/x';
import { ADDRESSDIDCHANGE, CITYDIDCHANGE, LOCATIONDIDCHANGE, SIGNIN, SIGNOUT, WAIMAICARTCHANGE } from './type';

const store = new Vuex.Store({
    state: {
        location: {
            latitude: 0,
            longitude: 0,
            speed: -1,
            accuracy: 65,
            verticalAccuracy: 65,
            horizontalAccuracy: 65
        },
        isSignined: false,
        userInfo: {},
        city: {
            name: '',
            lat: 0,
            lng: 0
        },
        address: {},
        chaoshiCartItems: [],
        shop: null,
        waimaiCart: {
            shop: null,
            products: []
        }
    },
    mutations: {
        [SIGNIN](state, userinfo) {
            state.isSignined = true;
            state.userInfo = userinfo;
        },
        [SIGNOUT](state) {
            state.isSignined = false;
            state.userInfo = null;
        },
        [LOCATIONDIDCHANGE](state, location) {
            state.location = location;
        },
        [CITYDIDCHANGE](state, city) {
            state.city = city;
        },
        [ADDRESSDIDCHANGE](state, address) {
            state.address = address;
        },
        [WAIMAICARTCHANGE](state, data) {
            state.waimaiCart = {
                ...state.waimaiCart,
                ...data
            };
        }
    },
    actions: {},
    getters: {}
});


module.exports = store;
